package com.gxcc3.ygps.web.controller.iot;

import com.gxcc3.ygps.common.annotation.Log;
import com.gxcc3.ygps.common.core.controller.BaseController;
import com.gxcc3.ygps.common.core.domain.AjaxResult;
import com.gxcc3.ygps.common.core.domain.entity.SysCompany;
import com.gxcc3.ygps.common.core.domain.entity.SysIotStorage;
import com.gxcc3.ygps.common.core.page.TableDataInfo;
import com.gxcc3.ygps.common.enums.BusinessType;
import com.gxcc3.ygps.common.utils.uuid.IdUtils;
import com.gxcc3.ygps.system.domain.SysConfig;
import com.gxcc3.ygps.system.service.ISysIotStorageService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 物联感知 冷库管理
 */
@RestController
@RequestMapping("/iot/storage")
public class SysIotStorageController extends BaseController {


    @Resource
    ISysIotStorageService storageService;



    /**
     * 冷库列表
     */
    @PreAuthorize("@ss.hasPermi('iot:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysIotStorage storage)
    {
        startPage();
        storage.setCompanyId(getCompanyId());
        List<SysIotStorage> list = storageService.selectStorageList(storage);
        return getDataTable(list);
    }


    /**
     * 新增冷库
     */
    @Log(title = "冷库监测", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('iot:storage:add')")
    public AjaxResult add(@Validated @RequestBody SysIotStorage storage){
        storage.setCreateBy(getUsername());
        storage.setCompanyId(getCompanyId());
        storage.setReportStatus("1");
        storage.setReportTempDeviceNo(IdUtils.randomSnowId());
        return toAjax(storageService.insertStorage(storage));
    }

    /**
     * 获取冷库信息
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('iot:storage:query')")
    public AjaxResult getStorage(@PathVariable Long id){
        return success(storageService.selectStorageById(id));
    }


    /**
     * 修改冷库信息
     */
    @PostMapping("/edit")
    @PreAuthorize("@ss.hasPermi('iot:storage:edit')")
    public AjaxResult edit(@Validated @RequestBody SysIotStorage storage){
        storage.setCreateBy(getUsername());
        return toAjax(storageService.updateStorage(storage));
    }


    /**
     * 修改冷库信息
     */
    @PostMapping("/remove/{ids}")
    @PreAuthorize("@ss.hasPermi('iot:storage:remove')")
    public AjaxResult delStorage(@PathVariable Long[] ids){
        return toAjax(storageService.delStorage(ids));
    }
}
